package com.web.servlet.bean;

import java.sql.Date;
import java.sql.Timestamp;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.web.servlet.manager.RedisManager;
import com.web.servlet.utils.TimeServerUtil;

public class UserInfo extends DataObject {
	
	final static String exclude = "|isDirty|op|playerType|";// 设置过滤的属性
	public static final Logger log = LoggerFactory.getLogger(UserInfo.class);
	static Gson g = new GsonBuilder().setExclusionStrategies(
			new ExclusionStrategy() {

				/**
				 * 设置要过滤的属性
				 */
				@Override
				public boolean shouldSkipField(FieldAttributes attr) {
					boolean b = false;
					// if (attr.getDeclaringClass() == PlayerModel.class)
					// {//可选指定过滤所属类
					b = exclude.contains("|" + attr.getName() + "|");
					// }
					return b;
				}

				/**
				 * 设置要过滤的类
				 */
				@Override
				public boolean shouldSkipClass(Class<?> clazz) {
					// 这里，如果返回true就表示此类要过滤，否则就输出
					return false;
				}
			}).create();
	// /////////////////json_id////////////////////////////////////////////////////////////////////
	
	public int user_id;
	public String user_name;
	public String pass_world;
	public String nick_name;
	public int gold;
	public int diamond;
	public String icon;
	public int sex;
	public Timestamp create_time;
	public Timestamp last_logintime;
	public String login_ip;
	public int score;
	public String signature;
	public String imei;
	public String channel;
	public int user_type;
	public String token;
	public int cardroom_id;
	public int table_id;
	
	
	/**
	 * 初始化 用户信息
	 * @param user_name
	 * @param pass_world
	 * @param nick_name
	 */
	public void initUser(String user_name,String pass_world,String nick_name){
		this.user_name = user_name;
		this.pass_world = pass_world;
		this.nick_name = nick_name;
		this.gold = 5000;
		this.icon  ="1";
		this.sex = 1;
		this.create_time = TimeServerUtil.getSysteCurTime();
		this.last_logintime = TimeServerUtil.getSysteCurTime();
		this.login_ip = "";
		this.score = 0;
		this.imei = "";
		this.channel = "";
		this.user_type = 0;
	}
	
	
	
	@Override
	public boolean load() {
		return false;
	}
	@Override
	public void save() {
		String value = pack();
		log.debug(value);
		RedisManager.getRedis().set(RedisKey.USERINFO+user_id, pack());
	}
	/**
	 * 生成json格式[好友列表需要单独存储]
	 * 
	 * @return
	 */
	public String pack() {
		return g.toJson(this);
	}
	
	/**
	 * 从json解析Player
	 * 
	 * @param json
	 */
	public static UserInfo parse(String json) {
		try {
			return g.fromJson(json, UserInfo.class);
		} catch (Exception e) {

			//log.error("parse error:" + Util.getExceptionStack(e));
		}
		return new UserInfo();
	}
	public int getUser_id() {
		return user_id;
	}
	public void setUser_id(int user_id) {
		this.user_id = user_id;
	}
	public String getUser_name() {
		return user_name;
	}
	public void setUser_name(String user_name) {
		this.user_name = user_name;
	}
	public String getPass_world() {
		return pass_world;
	}
	public void setPass_world(String pass_world) {
		this.pass_world = pass_world;
	}
	public String getNick_name() {
		return nick_name;
	}
	public void setNick_name(String nick_name) {
		this.nick_name = nick_name;
	}
	public int getGold() {
		return gold;
	}
	public void setGold(int gold) {
		this.gold = gold;
	}
	public int getDiamond() {
		return diamond;
	}
	public void setDiamond(int diamond) {
		this.diamond = diamond;
	}
	public String getIcon() {
		return icon;
	}
	public void setIcon(String icon) {
		this.icon = icon;
	}
	public int getSex() {
		return sex;
	}
	public void setSex(int sex) {
		this.sex = sex;
	}
	public Timestamp getCreate_time() {
		return create_time;
	}
	public void setCreate_time(Timestamp create_time) {
		this.create_time = create_time;
	}
	public Timestamp getLast_logintime() {
		return last_logintime;
	}
	public void setLast_logintime(Timestamp last_logintime) {
		this.last_logintime = last_logintime;
	}
	public String getLogin_ip() {
		return login_ip;
	}
	public void setLogin_ip(String login_ip) {
		this.login_ip = login_ip;
	}
	public int getScore() {
		return score;
	}
	public void setScore(int score) {
		this.score = score;
	}
	public String getSignature() {
		return signature;
	}
	public void setSignature(String signature) {
		this.signature = signature;
	}
	public String getImei() {
		return imei;
	}
	public void setImei(String imei) {
		this.imei = imei;
	}
	public String getChannel() {
		return channel;
	}
	public void setChannel(String channel) {
		this.channel = channel;
	}
	public int getUser_type() {
		return user_type;
	}
	public void setUser_type(int user_type) {
		this.user_type = user_type;
	}
	
	
}
